<!DOCTYPE html>
<html lang="zh-CN">
<link rel="stylesheet" href="zhuye.css">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
            color: black; /* 设置 body 文字颜色为黑色 */
        }

        .login-container {
            background-color: white;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
            width: 300px;
        }

        h2 {
            text-align: center;
            color: black; /* 设置 h2 文字颜色为黑色 */
        }

        .form-group {
            margin-bottom: 15px;
        }

        label {
            display: block;
            margin-bottom: 5px;
            color: black; /* 设置 label 文字颜色为黑色 */
        }

        input {
            width: 100%;
            padding: 8px;
            border: 1px solid #ccc;
            border-radius: 3px;
            color: black; /* 设置 input 文字颜色为黑色 */
        }

        button {
            width: 100%;
            padding: 10px;
            background-color: #007BFF;
            color: white; /* 按钮文字颜色保持白色，因为黑色在蓝色背景上不易读 */
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }

        button:hover {
            background-color: #0056b3;
        }

        #error-message {
            color: red; /* 错误信息颜色保持红色，以便突出显示 */
            text-align: center;
            margin-top: 10px;
        }
    </style>
</head>

<body>
<div id="app">
    <div class="login-container">
        <h2>用户登录</h2>
        <form id="login-form">
            <div class="form-group">
                <label for="username">用户名</label>
                <input type="text" id="username" required v-model="username">
            </div>
            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" id="password" required v-model="password">
            </div>
            <button type="button" @click="denglu">登录</button>
        </form>
        <div id="error-message"></div>
    </div>
</div>

<script src="js/vue.js"></script>
<script src="js/axios.min.js"></script>
<script>
    new Vue({
        el: '#app',
        data: {
            username: '',
            password: '',
        },
        methods: {
            denglu() {
                axios({
                    url: 'http://localhost:8888/yonghuxinxi/login',
                    method: 'get',
                    params: {
                        yonghuming: this.username,
                        denglumima: this.password
                    }
                }).then(resp => {
                    // 假设服务端返回的成功标志为 resp.data.success === true
                    if (resp.data.success) {
                        // 这里的 '主页的URL' 请替换为实际的主页地址
                        window.location.href = 'zhuye.html';
                    } else {
                        console.log('登录失败', resp.data);
                    }
                }).catch(error => {
                    console.log('登录请求出错', error);
                });
            }
        }
    });
</script>
</body>

</html>